package com.oracle.sbdb.dao;

import java.util.List;

import org.apache.ibatis.session.SqlSession;

import com.oracle.sbdb.model.Updates;

public class UpdatesDao {
	public Updates selectbyId(int updatesId){
		SqlSession session = SessionFactory.getSession();
		Updates res = session.selectOne("com.oracle.mybatis.UpdatesMapper.selectUpdates", updatesId);
		session.commit();
		session.close();
		return res;
	}
	
	public List<Updates> selectbyBugId(int bugId){
		SqlSession session = SessionFactory.getSession();
		List<Updates> res = session.selectList("com.oracle.mybatis.UpdatesMapper.selectUpdatesbyBugId", bugId);
		session.commit();
		session.close();
		return res;
	}
	
	public Updates selectLatestUpdate(int bugId){
		SqlSession session = SessionFactory.getSession();
		Updates res = session.selectOne("com.oracle.mybatis.UpdatesMapper.selectLatestUpdate", bugId);
		session.commit();
		session.close();
		return res;
	}
	
	public int selectCount() {
		SqlSession session = SessionFactory.getSession();
		int res = session.selectOne("com.oracle.mybatis.UpdatesMapper.selectUpdatesCount");
		session.commit();
		session.close();
		return res;
	}
	
	public void insert(Updates Updates) {
		SqlSession session = SessionFactory.getSession();
		session.selectOne("com.oracle.mybatis.UpdatesMapper.insertUpdates", Updates);
		session.commit();
		session.close();
	}
	
	public void update(Updates Updates) {
		SqlSession session = SessionFactory.getSession();
		session.selectOne("com.oracle.mybatis.UpdatesMapper.updateUpdates", Updates);
		session.commit();
		session.close();
	}
	
	public void delete(int updatesId) {
		SqlSession session = SessionFactory.getSession();
		session.selectOne("com.oracle.mybatis.UpdatesMapper.deleteUpdates", updatesId);
		session.commit();
		session.close();
	}
}
